package com.aaa.goodsservice.controller;

import com.aaa.common.entity.Order;
import com.aaa.goodsservice.po.Product;
import com.aaa.goodsservice.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: YuXin
 * @Date : Created in 2020/11/3 17:02
 * @ClassName : GoodsController
 * @Description :
 * @Package_Name : com.aaa.goodsservice.controller
 */
@RestController
@RequestMapping("/product")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询所有
     */
    @RequestMapping("selectAll")
    public Map selectAll() {
        List<Product> productsList = goodsService.selectAll();
        List<Order> orderList = goodsService.selectAllOrder();
        Map map = new HashMap();
        map.put("productsList", productsList);
        map.put("orderList", orderList);
        return map;
    }

    /**
     * 添加
     */
    @RequestMapping("insertSelective")
    public int insertSelective(Product record) {
        return goodsService.insertSelective(record);
    }

    /**
     * 根据主键删除
     */
    @RequestMapping("deleteByPrimaryKey")
    public int deleteByPrimaryKey(Long id) {
        return goodsService.deleteByPrimaryKey(id);
    }

    /**
     * 根据主键查询
     */
    @RequestMapping("selectByPrimaryKey")
    public Product selectByPrimaryKey(Long id) {
        return goodsService.selectByPrimaryKey(id);
    }

    /**
     * 修改
     */
    @RequestMapping("updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(Product record) {
        return goodsService.updateByPrimaryKeySelective(record);
    }

}
